package com.mall.shopping.services;

import com.mall.shopping.PanelDetailService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.PanelContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dal.persistence.PanelDetailMapper;
import com.mall.shopping.dal.persistence.PanelMapper;
import com.mall.shopping.dto.GoodRecommendResponse;
import com.mall.shopping.dto.NavigationDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lin
 * @Date: 2020/7/10 19:58
 */

@Service
public class PanelDetailServiceImpl implements PanelDetailService {

    @Autowired
    private PanelDetailMapper panelDetailMapper;

    @Autowired
    private PanelMapper panelMapper;

    @Autowired
    private PanelContentMapper panelContentMapper;

    @Autowired
    private PanelContentConverter panelContentConverter;

    @Autowired
    private ItemCatMapper itemCatMapper;


    @Override
    public GoodRecommendResponse getPanelDetail() {
        Integer id = 6;
        GoodRecommendResponse response = panelDetailMapper.getRecommend(6);
        response.setCode(ShoppingRetCode.SUCCESS.getCode());
        response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        return response;
    }

    @Override
    public List<GoodRecommendResponse> getHomePage() {
        List<GoodRecommendResponse> homePage = new ArrayList<>();
        List<Integer> panelIds = panelMapper.selectAllPanelId();
        if (panelIds == null){
            return homePage;
        }
        for (Integer panelId : panelIds) {
            GoodRecommendResponse element = panelDetailMapper.getRecommend(panelId);
            homePage.add(element);
        }
        return homePage;
    }

    @Override
    public List<NavigationDto> getNavigations() {
        Example example = new Example(PanelContent.class);
        example.createCriteria().andEqualTo("panelId", 0);
        List<PanelContent> panelContentList = panelContentMapper.selectByExample(example);
        return panelContentConverter.convertToList(panelContentList);
    }
}
